package com.halixun.d2app.adapter.holder;

import android.view.View;
import android.widget.TextView;

import com.halixun.d2app.R;
import com.halixun.d2app.adapter.PrintListAdapter;
import com.halixun.d2app.base.BasePrintInfo;
import com.halixun.d2app.base.BaseViewHolder;
import com.halixun.d2app.bean.print.BlueToothPrintInfo;
import com.halixun.d2app.bean.print.NetPrintInfo;
import com.halixun.d2app.bean.print.UsbPrintInfo;
import com.halixun.d2app.utils.ToastUtils;

/**
 * @ProjectName: D2App
 * @Package: com.halixun.d2app.adapter.holder.print
 * @ClassName: UsbPrintViewHolder
 * @Description: java类作用描述
 * @Author: hdx
 * @CreateDate: 2019/12/8 14:50
 * @UpdateUser: hdx
 * @UpdateDate: 2019/12/8 14:50
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class UsbPrintViewHolder extends BaseViewHolder<BasePrintInfo> {
    private TextView name;


    private TextView state;

    private UsbPrintInfo data;

    private PrintListAdapter.PrintListListener mPrintListListener;

    public UsbPrintViewHolder(View itemView) {
        super(itemView);
        initView();
        setListeners();
    }

    public UsbPrintViewHolder(View itemView, PrintListAdapter.PrintListListener printListListener) {
        this(itemView);
        this.mPrintListListener = printListListener;
    }

    private void setListeners() {
        itemView.setOnClickListener(v -> {
            if (null != mPrintListListener) {
                mPrintListListener.onPrintListItemClick(getAdapterPosition(), data);
            }
        });
    }

    private void initView() {
        name = itemView.findViewById(R.id.name);
        state = itemView.findViewById(R.id.state);
    }

    @Override
    public void setLayoutInfo(BasePrintInfo info) {
        this.data = (UsbPrintInfo) info;
        name.setText(data.name + "(" + data.id + ")");
        state.setText(data.isConnect ? "已连接" : "未连接");
    }
}
